#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
健康检查控制器（合并版本）
将路由和控制器合并到一个类中
"""

from flask import Blueprint, jsonify
from datetime import datetime

# API版本
API_VERSION = 'v1'

# 创建蓝图
health_bp = Blueprint('health', __name__, url_prefix='/api')

class HealthController:
    """
    健康检查控制器
    负责健康检查和API文档相关的路由
    """
    
    def __init__(self):
        """
        初始化控制器并注册路由
        """
        self._register_routes()
    
    def _register_routes(self):
        """
        注册路由
        """
        health_bp.route('/health', methods=['GET'])(self.health_check)
        health_bp.route('/docs', methods=['GET'])(self.api_docs)
    
    def health_check(self):
        """
        健康检查接口
        
        Returns:
            JSON: 健康状态信息
        """
        return jsonify({
            "success": True,
            "message": "微信后端API服务正常",
            "timestamp": datetime.now().isoformat(),
            "version": "1.0.0"
        })
    
    def api_docs(self):
        """
        API文档
        
        Returns:
            JSON: API文档信息
        """
        docs = {
            "title": "微信后端自动化系统 API",
            "version": "1.0.0",
            "description": "提供微信自动化操作的REST API接口",
            "endpoints": {
                "GET /api/health": "健康检查",
                "GET /api/status": "获取服务状态",
                "GET /api/config": "获取当前配置",
                "POST /api/config": "更新配置",
                "GET /api/friends": "获取好友列表",
                "GET /api/groups": "获取群聊列表",
                "POST /api/send-message": "发送消息",
                "GET /api/news/groups": "获取新闻推送群组",
                "POST /api/news/groups": "添加新闻推送群组",
                "DELETE /api/news/groups": "移除新闻推送群组",
                "POST /api/news/time": "设置新闻推送时间",
                "GET /api/news/test": "测试新闻获取",
                "GET /api/docs": "API文档"
            }
        }
        
        return jsonify({
            "success": True,
            "data": docs
        })

# 实例化控制器，确保路由被注册
health_controller = HealthController()